<template>
	<gui-page ref="guipage" :refresh="true" @reload="reload" :loadmore="true">
		<view slot="gBody">
			<view class="top">
				<view class="user flex-ac-jb">
					<view class="headImg">
						<view class="img">
							<!-- 						<gui-image :src="vuex_userInfo.headPortrait" :width="120" :height="120" borderRadius="50%" mode="aspectFill"></gui-image> -->
							<gui-imageLoading width="120" height="120" borderRadius="50%" :src="vuex_userInfo.headPortrait"
								mode="aspectFill" :showOpacity="true"></gui-imageLoading>
						</view>
						<image class="icon" src="../../static/user/vip-head.png" mode="widthFix" style="height: auto;">
						</image>
					</view>
					<view class="info flex-dc flex1">
						<view class="title flex-ac">
							<text class="f32">{{userInfo.username}}</text>
							<view class="btn f20 cfff" v-if="userInfo.isVip!=1">未开通会员</view>
							<view class="btn f20 cfff" v-else>{{userInfo.vipName}}</view>
						</view>
						<text class="phone f24 c333">{{$u.hidePhone(userInfo.phone,3,4)}}</text>
					</view>
					<view class="saveBtn" @tap="$u.to('/pages/user/userInfo')">
						<text class="gui-icons f26">&#xe613;</text>
						<text class="f22">设置</text>
					</view>
				</view>
				<view class="num-info flex-ac-jb">
					<view class="item flex-dc-ac" @tap="$u.to('/pages/user/mineFans')">
						<text class="f32">{{userInfo.fansCount}}</text>
						<text class="f24">我的粉丝</text>
					</view>
					<view class="item flex-dc-ac">
						<text class="f32">{{userInfo.invitationCode}}</text>
						<view class="f24 flex-ac" @tap="copyText(userInfo.invitationCode+'')">
							<text>用户ID</text>
							<view class="btn f16">复制</view>
						</view>
					</view>
					<view class="item flex-dc-ac">
						<text class="f32">{{userInfo.profitOrderCount}}</text>
						<text class="f24">佣金订单数</text>
					</view>
				</view>
			</view>
			<view class="content">
				<view class="vip-m cfff">
					<view class="top-m">
						<view class="vip-top bgfff flex-ac-jb f22" v-if="userInfo.isVip==1">
							<text class="flex1 c333">您的会员有效期截止到：{{userInfo.vipTime}}</text>
							<text class="gui-icons primary-color bold" @tap="$u.to('/pages/user/vipRecharge')">立即续费
								&#xe601;</text>
						</view>
						<view class="vip-top bgfff flex-ac-jb f22" v-else>
							<text class="flex1 c666">您的会员未开通/已过期</text>
							<text class="gui-icons primary-color bold" @tap="$u.to('/pages/user/vipRecharge')">
								立即充值 &#xe601;</text>
						</view>
						<text class="f26">可提现佣金</text>
						<view class="money flex-ac-jb" @tap="$u.to('/pages/user/withdraw?isUserFrom=true')">
							<text class="f48 bold">￥{{$u.priceFixed(userInfo.balance)}}</text>
							<view class="saveBtn">立即提现</view>
						</view>
					</view>
					<view class="bottom-m f24 flex-ac-jb">
						<text>今日收益：￥{{$u.priceFixed(userInfo.profit)}}</text>
						<text>累计获得收益：￥{{$u.priceFixed(userInfo.totalProfit)}}</text>
					</view>
				</view>
				<view class="tool-m bgfff radius10">
					<view class="item">我的服务</view>
					<!-- //vip需要判断 -->
					<view class="item flex-ac-jb" @tap="handleOpen()" v-if="!userInfo.isVip">
						<image src="../../static/user/tool1.png" mode="widthFix"></image>
						<text class="info flex1 f26">分销推广</text>
						<text class="gui-icons"><text class="primary-color">需先成为会员 </text> &#xe601;</text>
					</view>
					<view class="item flex-ac-jb" @tap="$u.to('/pages/user/commissionDetail')" v-if="userInfo.isVip">
						<image src="../../static/user/tool1.png" mode="widthFix"></image>
						<text class="info flex1 f26">佣金记录</text>
						<text class="gui-icons">&#xe601;</text>
					</view>
					<view class="item flex-ac-jb" @tap="$u.to('/pages/user/distributionOrder')" v-if="userInfo.isVip">
						<image src="../../static/user/tool2.png" mode="widthFix"></image>
						<text class="info flex1 f26">分销订单</text>
						<text class="gui-icons">&#xe601;</text>
					</view>
					<view class="item flex-ac-jb" @tap="createPoster" v-if="userInfo.isVip">
						<image src="../../static/user/tool3.png" mode="widthFix"></image>
						<text class="info flex1 f26">邀请海报</text>
						<text class="gui-icons">&#xe601;</text>
					</view>
					<view class="item flex-ac-jb" @tap="$u.to('/pages/user/helpCenter')">
						<image src="../../static/user/tool4.png" mode="widthFix"></image>
						<text class="info flex1 f26">帮助中心</text>
						<text class="gui-icons">&#xe601;</text>
					</view>
					<view class="item flex-ac-jb" @tap="$u.to('/pages/user/customerService')">
						<image src="../../static/user/tool5.png" mode="widthFix"></image>
						<text class="info flex1 f26">联系客服</text>
						<text class="gui-icons">&#xe601;</text>
					</view>
			
				</view>
			</view>
			<!-- 居中弹出 -->
			<gui-popup ref="guipopup" width="480rpx">
				<view class="gui-relative gui-box-shadow bgfff popup radius15 f26">
					<view class="close-btn gui-icons bold flex-ac-je c999" @tap="handleClose()">&#xe610;</view>
					<view class="popup-con flex-dc-ac">
						<text class="bold title f28">温馨提示</text>
						<image class="popup-img" src="../../static/index/vipTip.png" mode="widthFix" style="height: auto;">
						</image>
						<text>使用工具功能</text>
						<text class="primary-color">请先充值成为会员</text>
						<view class="saveBtn" @tap="goPay">立即充值</view>
					</view>
			
				</view>
			</gui-popup>
			<poster ref="poster" :bgImg="posterBg" :synopsis="synopsis"></poster>
		</view>
	</gui-page>
</template>

<script>
	import poster from '@/components/poster/poster.vue'
	export default {
		components: {
			poster
		},
		data() {
			return {
				userInfo: {},
				posterBg: '',
				synopsis: ''
			}
		},
		onLoad() {
			this.getPoster()
		},
		onShow() {
			this.getUser()
		},
		methods: {
			reload() {
				this.getUser(true)
			},
			goPay() {
				this.handleClose()
				this.$u.to('/pages/user/vipRecharge')
			},
			handleOpen: function() {
				this.$refs.guipopup.open();
			},
			handleClose: function() {
				this.$refs.guipopup.close();
			},
			createPoster() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 0
				})
				setTimeout(() => {
					this.$refs.poster.initPoster()
				}, 100)
			},
			getPoster() {
				this.$http.get('/api/placard').then(res => {
					let result = res.data
					console.log('邀请海报', result)
					if (result.length) {
						this.posterBg = result[0].image
						this.synopsis = result[0].synopsis
					}
				})
			},
			getUser(isReload) {
				this.$http.post('/api/oauth/info').then(res => {
					let result = res.data
					console.log('用户信息', result)
					this.userInfo = result
					this.$u.vuex('vuex_userInfo', result);
					if(isReload) {
						this.$refs.guipage.endReload();
					}
				}).catch(err => {
					if(isReload) {
						this.$refs.guipage.endReload();
					}
				})
			},
			copyText(text) {
				this.$u.copyText(text, (res) => {
					this.$u.msg('已复制！')
				})
			}
		}
	}
</script>

<style lang="less">
	page {
		background: #FFF2F2;
	}

	.top {
		background: url(../../static/index/banner.jpg) no-repeat;
		background-size: 100% 100%;
		padding: 120rpx 0 23rpx 30rpx;

		.user {
			.headImg {
				position: relative;
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
				border: 2px solid #fff;

				.img {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}

				.icon {
					position: absolute;
					right: -24rpx;
					top: -24rpx;
					width: 52rpx;
				}
			}

			.info {
				margin: 0 20rpx;

				.title {
					margin-bottom: 14rpx;

					.btn {
						padding: 4rpx 8rpx;
						background: linear-gradient(180deg, #FFB272 0%, #FF7400 100%);
						margin-left: 15rpx;
						border-radius: 4rpx;
					}
				}
			}

			.saveBtn {
				width: 128rpx;
				height: 56rpx;
				background: #FF5151;
				border-radius: 100rpx 0rpx 0rpx 100rpx;

				.gui-icons {
					margin-right: 10rpx;
				}
			}
		}

		.num-info {
			padding: 30rpx 30rpx 0 0;

			.item {
				width: 230rpx;

				.f32 {
					margin-bottom: 16rpx;
				}

				.btn {
					padding: 2rpx 10rpx;
					border-radius: 4rpx;
					border: 1rpx solid #FF5151;
					margin-left: 4rpx;
					color: #FF5151;
				}
			}
		}
	}

	.content {
		padding: 0 30rpx 30rpx 30rpx;
	}

	.vip-m {
		background: linear-gradient(135deg, #FF7272 0%, #FF0019 100%);
		box-shadow: inset 1rpx 1rpx 0rpx 1rpx rgba(255, 255, 255, 0.5);
		border-radius: 15rpx 15rpx 0 0;

		.top-m {
			padding: 26rpx 30rpx;
			border: 1rpx solid rgba(255, 255, 255, 0.3);

			.vip-top {
				padding: 20rpx;
				margin-bottom: 15rpx;
			}

			.money {
				.saveBtn {
					width: 184rpx;
					height: 64rpx;
					background: #000000;
					font-size: 24rpx;
				}
			}
		}

		.bottom-m {
			padding: 16rpx 30rpx;
		}
	}

	.tool-m {
		margin-top: 20rpx;

		.item {
			padding: 26rpx 30rpx;
			border-top: 1px solid #e9e9e9;

			image {
				width: 26rpx;
			}

			.info {
				margin: 0 20rpx;
			}
		}
	}

	.popup {
		position: relative;
		padding: 52rpx 80rpx 45rpx 80rpx;

		.close-btn {
			position: absolute;
			right: 0;
			top: 0;
			width: 100rpx;
			height: 60rpx;
			padding-right: 20rpx;
		}

		.popup-con {
			.title {}

			.popup-img {
				width: 215rpx;
				margin: 20rpx 0 30rpx 0;
			}

			.saveBtn {
				width: 269rpx;
				height: 64rpx;
				font-size: 24rpx;
				margin-top: 36rpx;
			}
		}
	}
</style>